package com.sos.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sos.dto.OrderSearch;
import com.sos.entity.BasePage;
import com.sos.entity.LayuiR;
import com.sos.entity.dto.DoctorDto;
import com.sos.entity.dto.UserOrder;
import com.sos.entity.po.Doctor;
import com.sos.entity.po.Order;
import com.sos.entity.po.OrderDetail;
import com.sos.entity.po.Subject;
import com.sos.service.ProcessService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 港某人
 * @date 2021/3/7 14:27
 */
@RestController
@RequestMapping(value = "process")
public class ProcessController {

    @Resource
    ProcessService processService;

    @RequestMapping(value = "createOrder", method = {RequestMethod.POST})
    LayuiR<String> createOrder(@RequestBody UserOrder userOrder) {
        String order = processService.createOrder(userOrder);
        return LayuiR.msg(order);
    }

    @RequestMapping(value = "getOrderToday", method = {RequestMethod.POST})
    LayuiR<List<Order>> getOrderToday(BasePage basePage) {
        Page<Order> orderToday = processService.getOrderToday(basePage);
        return LayuiR.data(orderToday.getRecords(), orderToday.getTotal());
    }

    @RequestMapping(value = "getOrderByUserAccount", method = {RequestMethod.POST})
    LayuiR<List<OrderDetail>> getOrderByUserAccount(OrderSearch orderSearch) {
        Page<OrderDetail> page = processService.getOrderByUserAccount(orderSearch);
        return LayuiR.data(page.getRecords(), page.getTotal());
    }

    @RequestMapping(value = "getAllSubject", method = {RequestMethod.POST})
    LayuiR<List<Subject>> getAllSubject() {
        List<Subject> allSubject = processService.getAllSubject();
        return LayuiR.data(allSubject, allSubject.size());
    }

    @RequestMapping(value = "getDoctor", method = {RequestMethod.POST})
    LayuiR<List<Doctor>> getDoctor(DoctorDto doctorDto) {
        Page<Doctor> doctor = processService.getDoctor(doctorDto);
        return LayuiR.data(doctor.getRecords(), doctor.getTotal());
    }


}
